package zq.cn.activity;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by ZQ on 2016/4/20.
 */
public class MyView extends View{

    public MyView(Context context) {
        super(context);
    }

    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        //用来刷真
        super.onDraw(canvas);

        Paint paint = new Paint();
        paint.setColor(Color.BLUE);
        paint.setTextSize(18);
        canvas.drawText("Hello World", 100, 100, paint);

        paint.setColor(Color.RED);
        canvas.drawLine(100, 100, 200, 200, paint);

        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawRect(100, 200, 400, 400, paint);

        canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.book), 150, 500, paint);
    }
}
